<template>
    <div class="app-detail">
        <el-card class="box-card">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    <!-- {{$t('inventoryManagement.baseInfo')}} -->
                </div>
            </div>
            <el-form :model="viewModel" ref="planForm" label-width="88px" :rules="rules">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.supplierName')" prop="supplierName">
                            <supplier-dialog v-model="viewModel.supplierName" @callback="(row)=>supplierDataCallback(row)" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                            <el-input v-model="viewModel.supplierCode" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.supplierType')" prop="supplierType">
                            <el-select v-model="viewModel.supplierType" :placeholder="$t('public.selectPl')" style="width:100%;" disabled clearable size="small">
                                <el-option key="0" label="潜在供方" value="0" />
                                <el-option key="1" label="合格供方" value="1" />
                                <el-option key="2" label="冻结" value="2" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                            <material-dialog v-model="viewModel.materialName" @callback="(row)=>materialDataCallback(row)" buildVersion :params="{inspectionId:id!='0'?id:undefined}" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                            <el-input v-model="viewModel.materialCode" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.materialType')" prop="materialType">
                            <el-input v-model="viewModel.materialType" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                            <el-input v-model="viewModel.maturity" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inspectionManagement.plantArea')" prop="factoryName">
                            <el-select filterable v-model="viewModel.factoryName" :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.plantArea')})" style="width:100%;" clearable @change="factoryChange" size="small">
                                <el-option v-for="(item) in factoryList" :key="item.id" :label="item.factoryName" :value="item.factoryName" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.frequency')" prop="planFrequency">
                            <el-select v-model="viewModel.planFrequency" :placeholder="$t('public.selectPl')" style="width:100%;" clearable size="small">
                                <el-option key="p" label="批" value="p" />
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inventoryManagement.frequencyValue')" prop="frequencyValue">
                            <el-input v-model="viewModel.frequencyValue" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inspectionManagement.version')" prop="version">
                            <el-input v-model="viewModel.version" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :md="6" :sm="6" :xs="6">
                        <el-form-item :label="$t('inspectionManagement.revisionDrawing')" prop="drawingsVersion">
                            <el-input v-model="viewModel.drawingsVersion" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%">
                            <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 6}" v-model="viewModel.description" maxlength="1000">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item :label="$t('inspectionManagement.uploadDrawing')" prop="uploadDrawing" style="width:100%">
                            <file-upload-input v-model="viewModel.file" @change="picChange"></file-upload-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item :label="$t('inspectionManagement.uploadAttachments')" prop="uploadAttachments" style="width:100%">
                            <file-upload v-model="viewModel.uploadAttachments" @change="(fileList)=>fileChange(fileList)"></file-upload>
                        </el-form-item>
                    </el-col>

                </el-row>

            </el-form>
        </el-card>
        <el-card class="box-card" style="margin-top:24px;">
            <div class="app-container">
                <div class="container-header">
                    <div class="hign-line"></div>
                    <div class="header-left">
                        {{$t('inventoryManagement.inspectionInfo')}}
                    </div>
                </div>
                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">{{$t('public.add')}}</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSelectTemplate">{{$t('inspectionManagement.selectTemplate')}}</el-button>
                    </el-col>
                </el-row>
                <div class="container-table">
                    <el-table stripe max-height="350" border v-loading="loading" :data="typeList" :key="itemsKey" @selection-change="handleSelectionChange">
                        <el-table-column :label="$t('inventoryManagement.inspectionItems')" align="left" prop="inspectionItems" minWidth="160">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.projectName" filterable placeholder="请选择" @change="changeProject(scope)" size="mini">
                                    <el-option size="mini" v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.projectName">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.code')" align="left" prop="projectCode" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input disabled v-model="scope.row.projectCode" size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspectionTypeUnit')" minWidth="130" align="left" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.unitName" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in unitList" :key="item.unitName" :label="item.unitName" :value="item.unitName">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inspectionManagement.aroundFrequency')" minWidth="110" align="left" prop="itemFrequency" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.itemFrequency" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in frequencyOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="itemFrequencyValue" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.itemFrequencyValue" clearable size="small" />
                            </template>
                        </el-table-column>

                        <el-table-column :label="$t('inventoryManagement.inspectionType')" minWidth="120" align="left" prop="checkoutTypeCopy">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.checkoutTypeCopy" filterable placeholder="请选择" size="mini" @change="(e)=>changeCheckoutType(e,scope)">
                                    <el-option size="mini" v-for="(item,index) in dict.type.NYIQC_CHECK_TYPE" :key="index" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>

                        <el-table-column :label="$t('inventoryManagement.decimalPlaces')" align="left" prop="decimalPlace" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.decimalPlace" v-show="scope.row.checkoutType!='布尔型'" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.lowerValue')" align="left" prop="lowerLimit" minWidth="100" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-show="scope.row.checkoutType!='布尔型'" v-model="scope.row.lowerLimit" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.upperValue')" minWidth="100" align="center" prop="upperLimit">
                            <template slot-scope="scope">
                                <el-input v-show="scope.row.checkoutType!='布尔型'" v-model="scope.row.upperLimit" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.targetValue')" align="left" prop="targetValue" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.targetValue" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingOne" minWidth="140" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.samplingOne" @change="(e)=>changeSampling(e,scope)" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in samplingSchemeOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingOptions')" align="left" prop="samplingOptions" minWidth="260">
                            <template slot-scope="scope">

                                <el-select v-model="scope.row.samplingTwo" filterable placeholder="请选择" size="mini" style="width:48%;margin-left:5px" v-if="scope.row.samplingOne=='GB/T2828.1-2012'||scope.row.samplingOne=='C=0'">
                                    <el-option size="mini" v-for="item in samplingLevelTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <el-select v-model="scope.row.samplingThree" filterable placeholder="请选择" size="mini" style="width:48%" v-if="scope.row.samplingOne=='GB/T2828.1-2012'">
                                    <el-option size="mini" v-for="item in samplingLevelOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <el-input placeholder="百分比" min="0" style="width:90%" type="number" size="mini" v-model="scope.row.samplingTwo" v-if="scope.row.samplingOne=='百分比'">
                                </el-input>
                                <span v-if="scope.row.samplingOne=='百分比'" style="margin-left:3px">%</span>
                                <el-input-number style="width:48%" v-if="scope.row.samplingOne=='固定抽样'" size="small" v-model="scope.row.samplingTwo" controls-position="right" :min="0"></el-input-number>
                                <!-- <el-select v-model="scope.row.samplingThree" filterable size="mini" style="width:48%;margin-left:5px" v-if="scope.row.samplingOne=='固定抽样'">
                                    <el-option size="mini" v-for="item in samplingFixedTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select> -->
                                <el-select v-model="scope.row.samplingThree" style="width:48%" filterable size="mini" v-if="scope.row.samplingOne=='C=0'">
                                    <el-option size="mini" v-for="(item,index) in samplingMethodCOptions" :key="index" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>

                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.testMethod')" align="left" prop="detectionOne" :minWidth="200" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.detectionOne" filterable placeholder="请选择" size="mini" :style="scope.row.detectionOne=='量具'?'width:48%;margin-right:3px;float:left':'width:100%'">
                                    <el-option size="mini" v-for="item in testMethodOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <measuring-tool-dialog v-show="scope.row.detectionOne=='量具'" v-model="scope.row.detectionTwo" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="symbol" minWidth="110" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.symbol" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in specialCharacteristicsOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('public.opera')" fixed="right" align="center" width="100">
                            <template slot-scope="scope">
                                <div class="action-wrap">
                                    <table-body-btn type="delete" @click.native="handleDelete(scope)" />
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
        </el-card>
        <div class="submit-footer">
            <el-button icon="el-icon-close" size="small" @click="closeTab" class="drawer-close">{{$t('public.close')}}</el-button>
            <el-button type="primary" @click="submitForm" icon="el-icon-check" size="small">{{$t('public.submit')}}</el-button>
        </div>
        <template-dialog :visible.sync="templateVisible" @callback="(row)=>templateDataCallback(row)" />
    </div>

</template>

<script>
import {getType, refreshCache,} from '@/api/basic/dict/type'
import {getNoticeList} from '@/api/system/message'
import {listFactory} from '@/api/basic/factory'
import {listProject} from '@/api/basic/project'
import {listCheckoutUnit} from '@/api/basic/checkoutUnit'

import {addInspectionPlan, getSamplingPlan, getVersion,} from '@/api/inspectionManagement/inspectionManagement'
import FileUploadInput from '@/components/FileUploadInput'
import SupplierDialog from '@/views/components/SupplierDialog'
import MaterialDialog from '@/views/components/MaterialDialog'
import TemplateDialog from '@/views/components/TemplateDialog'
import MeasuringToolDialog from '@/views/components/MeasuringToolDialog'

export default {
    name: 'addInspectionPlan',
    dicts: ['sys_normal_disable', 'NYIQC_CHECK_TYPE'],
    components: {
        FileUploadInput,
        SupplierDialog,
        MaterialDialog,
        TemplateDialog,
        MeasuringToolDialog,
    },
    data() {
        return {
            direction: 'rtl',
            addInspectionExemption: false,
            templateVisible: false,
            drawer: false,
            approvalOpen: false,
            viewInspectionExemption: false,
            projectList: [],
            inspectionOptions: [
                {
                    value: '1',
                    label: '检验项1',
                },
                {
                    value: '2',
                    label: '检验项2',
                },
            ],
            inspectionTypeUnitOptions: [
                {
                    value: '1',
                    label: '单位1',
                },
                {
                    value: '2',
                    label: '单位2',
                },
            ],
            frequencyOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
                {
                    value: '年',
                    label: '年',
                },
                {
                    value: '季',
                    label: '季',
                },
                {
                    value: '月',
                    label: '月',
                },
                {
                    value: '日',
                    label: '日',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: 'GB/T2828.1-2012',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '百分比',
                    label: '百分比',
                },
                {
                    value: '固定抽样',
                    label: '固定抽样',
                },
                {
                    value: 'C=0',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '目测',
                    label: '目测',
                },
                {
                    value: '量具',
                    label: '量具',
                },
                {
                    value: '验证',
                    label: '验证',
                },
                {
                    value: 'ny-iqc作业指导书',
                    label: 'ny-iqc作业指导书',
                },
                {
                    value: '核对COA',
                    label: '核对COA',
                },
            ],
            samplingLevelOptions: [
                {
                    value: 'S-1',
                    label: 'S-1',
                },
                {
                    value: 'S-2',
                    label: 'S-2',
                },
                {
                    value: 'S-3',
                    label: 'S-3',
                },
                {
                    value: 'S-4',
                    label: 'S-4',
                },
                {
                    value: 'Ⅰ',
                    label: 'Ⅰ',
                },
                {
                    value: 'Ⅱ',
                    label: 'Ⅱ',
                },
                {
                    value: 'Ⅲ',
                    label: 'Ⅲ',
                },
            ],
            samplingMethodCOptions: [
                {
                    value: '0.01',
                    label: '0.01',
                },
                {
                    value: '0.015',
                    label: '0.015',
                },
                {
                    value: '0.025',
                    label: '0.025',
                },
                {
                    value: '0.04',
                    label: '0.04',
                },
                {
                    value: '0.1',
                    label: '0.1',
                },
                {
                    value: '0.15',
                    label: '0.15',
                },
                {
                    value: '0.25',
                    label: '0.25',
                },
                {
                    value: '0.4',
                    label: '0.4',
                },
                {
                    value: '0.65',
                    label: '0.65',
                },
                {
                    value: '1',
                    label: '1',
                },
                {
                    value: '1.5',
                    label: '1.5',
                },
                {
                    value: '4',
                    label: '4',
                },
                {
                    value: '6.5',
                    label: '6.5',
                },
                {
                    value: '10',
                    label: '10',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '正常',
                    label: '正常',
                },
                {
                    value: '放宽',
                    label: '放宽',
                },
                {
                    value: '加严',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
            ],
            specialCharacteristicsOptions: [
                {
                    value: '空',
                    label: '空',
                },
                {
                    value: 'CC',
                    label: 'CC',
                },
                {
                    value: 'SC',
                    label: 'SC',
                },
            ],
            addModel: {},
            viewModel: {
                file: null,
                version: null,
                inspectionExemptionPlan: '1',
                uploadAttachments: null,
                supplierName: null,
                materialName: null,
                supplierType: null,
                maturity: null,
            },
            editModel: {},
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [
                {
                    samplingOne: null,
                    samplingTwo: null,
                    samplingThree: null,
                    measuringTool: null,
                    inspectionType: '1',
                    specialCharacteristics: '0',
                    projectCode: null,
                },
            ],
            factoryList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            unitList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                noticeTitle: undefined,
                noticeType: undefined,
                hasRead: undefined,
                createTime: undefined,
            },
            // 表单参数
            form: {},
            itemsKey: 0,
            otherFileList: [],
            picFileList: [],
            samplingPlanList: [],
            // 表单校验
            rules: {
                materialName: [
                    {
                        required: true,
                        message: this.$t('formValidation.materialNameCannotBeEmpty'),
                        trigger: 'change',
                    },
                ],
                supplierName: [
                    {
                        required: true,
                        message: '供应商名称不能为空',
                        trigger: 'change',
                    },
                ],
                factoryName: [
                    {
                        required: true,
                        message: this.$t('formValidation.factoryAreaCannotBeEmpty'),
                        trigger: 'change',
                    },
                ],
                planFrequency: [
                    {
                        required: true,
                        message: '频率不能为空',
                        trigger: 'change',
                    },
                ],
                version: [
                    {
                        required: true,
                        message: this.$t('formValidation.versionNumberCannotBeEmpty'),
                        trigger: 'change',
                    },
                ],
            },
            fullscreen: false,
        }
    },
    created() {
        this.getFactoryList()
        this.getList()
        this.getProjectList()
        this.getUnitList()
        this.getSamplingPlan()
    },
    methods: {
        checkoutTypeCopyFilter(row) {
            const current = this.dict.type.NYIQC_CHECK_TYPE.find((io) => {
                return io.value === row
            })
            return current ? current.label : ''
        },
        changeSampling(e, scope) {
            console.log(scope.$index)
            this.typeList[scope.$index].samplingTwo = null
            this.typeList[scope.$index].samplingThree = null
        },
        changeCheckoutType(e, scope) {
            let data = this.checkoutTypeCopyFilter(e)
            e.includes('boole')
                ? (this.typeList[scope.$index].checkoutType = '布尔型')
                : (this.typeList[scope.$index].checkoutType = '数值')
            this.typeList[scope.$index].checkoutTypeCopy = data
        },
        changeSamplingOption(e, scope) {
            console.log(e)
            this.typeList[scope.$index].samplingTwo = e
            this.$forceUpdate()
        },
        getSamplingPlan() {
            getSamplingPlan().then((res) => {
                this.samplingPlanList = res.rows
            })
        },
        changeProject(e) {
            let obj = this.projectList.find((item) => {
                return item.projectName === e.row.projectName
            })
            this.typeList[e.$index].projectCode = obj.projectCode
            this.typeList[e.$index].projectId = obj.projectId
        },
        getProjectList() {
            listProject().then((res) => {
                this.projectList = res.rows
            })
        },
        getUnitList() {
            listCheckoutUnit().then((res) => {
                this.unitList = res.rows
            })
        },
        fileChange(fileList) {
            this.otherFileList = fileList
        },
        picChange(fileList) {
            this.picFileList = fileList
        },
        getFactoryList() {
            listFactory().then((res) => {
                this.factoryList = res.rows
            })
        },
        factoryChange(e) {
            let obj = this.factoryList.find((item) => {
                return item.factoryName === e
            })
            this.viewModel.factoryCode = obj.factoryCode
            this.currentFactoryName = e
            this.buildVersion()
        },
        templateDataCallback(rows) {
            this.typeList = rows
        },
        supplierDataCallback(row) {
            this.viewModel.supplierCode = row.supplierCode
            this.viewModel.supplierName = row.supplierName
            this.viewModel.supplierType = row.supplierCategory
            this.buildVersion()
        },
        materialDataCallback(row) {
            this.viewModel.materialCode = row.materialCode
            this.viewModel.materialName = row.materialName
            this.viewModel.materialType = row.materialType
            this.viewModel.maturity = row.maturity
            this.viewModel.materialTypeName = row.materialTypeName
            this.buildVersion()
        },
        buildVersion() {
            if (
                this.viewModel.materialCode &&
                this.currentFactoryName
            ) {
                getVersion({
                    factoryName: this.currentFactoryName,
                    materialCode: this.viewModel.materialCode,
                    supplierCode: this.viewModel.supplierCode,
                }).then((res) => {
                        if(res.code == 200) return this.viewModel.version = res.msg
                    })
                    .catch((error) => {
                        this.viewModel.version = undefined
                    })
            }
        },
        closeTab() {
            this.$router.push({ path: '/inspect/inspectionPlan' })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.typeList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            getNoticeList(this.queryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    //   this.typeList = response.rows;
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.typeList.push({
                samplingOne: null,
                samplingTwo: null,
                samplingThree: null,
                measuringTool: null,
                inspectionType: '1',
                specialCharacteristics: '0',
                projectCode: null,
            })
        },
        handleSelectTemplate() {
            this.templateVisible = true
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            console.log(this.loading)
            if (this.loading) {
                return
            }
            let fileId = []
            this.otherFileList.forEach((io) => {
                fileId.push(io.id)
            })
            this.picFileList.forEach((io) => {
                fileId.push(io.response.data.id)
            })

            if (this.picFile && this.picFile.id) {
                fileId.push(this.picFile.id)
            }
            let submitData = {
                ...this.viewModel,
                checkItemList: this.typeList,
                drawingsBizType: 'UPLOAD_FILE',
                elseBizType: 'UPLOAD_FILE_OTHERS',
                fileId: fileId.join(','),
            }
            console.log(fileId.join(','))
            console.log(JSON.stringify(submitData))
            this.$refs.planForm.validate((valid) => {
                if (valid) {
                    this.loading = true
                    addInspectionPlan(submitData)
                        .then((res) => {
                            if (res.code == 200) {
                                this.$modal.msgSuccess('操作成功!')
                                this.$router.push({
                                    path: '/inspect/inspectionPlan',
                                })
                            } else {
                                this.$modal.msgError(res.msg)
                            }
                        })
                        .catch((error) => {
                            this.loading = false
                        })
                }
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            if (this.typeList.length === 1) {
                this.$modal.msgWarning('请至少保留一条检验项!')
                return
            }
            this.typeList.splice(row.$index, 1)
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.viewInspectionExemption = true
            //   if(row.hasRead == 0){
            //     readNotice(row.noticeId).then(res=>{
            //       if(res.code == 200){
            //         this.handleQuery()
            //       }
            //     })
            //   }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            this.drawer = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'system/dict/type/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    // max-height: calc(100vh - 600px);
    overflow: auto;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
}
.app-detail {
    max-height: calc(100vh - 180px);
    overflow: auto;
}
</style>
